package com.ruicar.afs.cloud.workflow.gwt.componts;

import com.ruicar.afs.cloud.workflow.gwt.processor.AfsWorkFLowQueryProcessor;
import com.ruicar.afs.cloud.workflow.gwt.processor.AfsWorkFlowNoticeProcessor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
@AllArgsConstructor
public class GwtWorkFlowService {
    private final List<AfsWorkFLowQueryProcessor> afsWorkFLowQueryProcessors;
    private final List<AfsWorkFlowNoticeProcessor> afsWorkFlowNoticeProcessors;
    public static final Map<String, AfsWorkFLowQueryProcessor> QUERY_PROCESSOR = new HashMap<>();
    public static final Map<String, AfsWorkFlowNoticeProcessor> NOTICE_PROCESSOR = new HashMap<>();

    @PostConstruct
    public void init() {
        afsWorkFLowQueryProcessors
                .stream()
                .forEach(afsWorkFLowQueryProcessor -> {
                    for (String key : afsWorkFLowQueryProcessor.afsFLowKeys()) {
                        QUERY_PROCESSOR.put(key, afsWorkFLowQueryProcessor);
                    }
                });
        afsWorkFlowNoticeProcessors
                .stream()
                .forEach(afsWorkFlowNoticeProcessor -> {
                    for (String key : afsWorkFlowNoticeProcessor.afsFLowKeys()) {
                        NOTICE_PROCESSOR.put(key, afsWorkFlowNoticeProcessor);
                    }
                });
    }
}
